import request from './base'
let token = window.localStorage.getItem('token') || ''
export const baseGet = (params, url, _this) => {
  // /*基本get请求*/
  // params = getRequestParam(params)
  params.token = token
  return request.get(url, {params}).then(response => {
    if (response.error === 0) {
      return response.data
    } else if (response.error !== 0) {
      // _this.$vux.toast.show({type: 'cancel', text: response.msg ? response.msg : response.msg})
      return response
    }
  }).catch(function (error) {
    _this.$vux.toast.show({type: 'cancel', text: '服务器繁忙'})
    console.log(error)
    return null
  })
}
export const basePost = (params, url, _this) => {
  // /*基本get请求*/
  // params = getRequestParam(params)
  params.token = token
  return request.post(url, {params}).then(response => {
    if (response.error === 0) {
      return response.data
    } else if (response.error !== 0) {
      // _this.$vux.toast.show({type: 'cancel', text: response.msg ? response.msg : response.msg})
      return response
    }
  }).catch(function (error) {
    _this.$vux.toast.show({type: 'cancel', text: '服务器繁忙'})
    console.log(error)
    return null
  })
}
export const handleLocalStorage = (method, key, value) => {
  switch (method) {
    case 'get': {
      let temp = window.localStorage.getItem(key)
      if (temp) {
        return temp
      } else {
        return false
      }
    }
    case 'set': {
      window.localStorage.setItem(key, value)
      break
    }
    case 'remove': {
      window.localStorage.removeItem(key)
      break
    }
    default: {
      return false
    }
  }
}
